package com.gonsin.gview.model.dynamic.form;

import com.gonsin.gview.model.GFormItemModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@ApiModel("静态图片框")
@AllArgsConstructor
@NoArgsConstructor
public class DynamicImage extends DynamicFormItem {

    @ApiModelProperty("text_input表示文本框，还有check_box\\file\\radio\\rich_text\\text_input\\tree_check_box\\tree_selector")
    private final String itemType = "image";

    @ApiModelProperty("显示对应的值")
    private String keyName;

    @ApiModelProperty("显示字段名称")
    private String name;

    @ApiModelProperty("和keyName作用相同，keyName是直接显示对应的字段，value是动态显示字段值\n" +
            "使用mustache注入，如果value为\"\"时，显示keyName对应的值，如果value非空时显示value的内容\n" +
            "用法例如：\n" +
            "{{item.createTime}}\n" +
            "/files/{{filename}}")
    private String value;

    @ApiModelProperty("根据情况显示")
    private String showIf = "1";



    public static DynamicImageBuilder builder() {
        return new DynamicImageBuilder();
    }
    public static final class DynamicImageBuilder {
        @ApiModelProperty("显示对应的值")
        private String keyName;

        @ApiModelProperty("显示字段名称")
        private String name;

        @ApiModelProperty("和keyName作用相同，keyName是直接显示对应的字段，value是动态显示字段值\n" +
                "使用mustache注入，如果value为\"\"时，显示keyName对应的值，如果value非空时显示value的内容\n" +
                "用法例如：\n" +
                "{{item.createTime}}\n" +
                "/files/{{filename}}")
        private String value;

        @ApiModelProperty("根据情况显示")
        private String showIf = "1";

        private DynamicImageBuilder() {
        }

        public DynamicImageBuilder keyName(String keyName) {
            this.keyName = keyName;
            return this;
        }

        public DynamicImageBuilder name(String name) {
            this.name = name;
            return this;
        }

        public DynamicImageBuilder value(String value) {
            this.value = value;
            return this;
        }

        public DynamicImageBuilder showIf(String showIf) {
            this.showIf = showIf;
            return this;
        }

        public DynamicImage build() {
            DynamicImage dynamicImage = new DynamicImage();
            dynamicImage.setKeyName(keyName);
            dynamicImage.setName(name);
            dynamicImage.setValue(value);
            dynamicImage.setShowIf(showIf);
            return dynamicImage;
        }
    }
}
